package com.probiz.estore.common.model.system.base;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

import com.probiz.estore.common.model.system.Region;
import com.probiz.estore.core.util.ContextUtil;
import com.probiz.estore.system.service.RegionManager;

public class RegionTbl extends com.probiz.estore.core.model.BaseObject implements Serializable {

    protected Integer regionId;
	protected String regionCode;
	protected Integer regionType;
	protected String regionName;
	protected String zipCode;
	protected String telephoneCode;
	protected String description;
	protected String regionIcon;
	protected Short status;
	protected Integer sortOrder;
	protected Integer version;
	protected Integer createBy;
	protected java.util.Date createTime;
	protected Integer updateBy;
	protected java.util.Date updateTime;
	/**
	 * 父区域
	 */
	protected Region parent;
	/**
	 * 子区域
	 */
	protected Set children = new HashSet();
	protected Set regionItems = new HashSet();  //包含的子区域
	protected Set regionSubItems = new HashSet(); //引用到该区域的子区域
	protected Set shippingRates = new HashSet();
	
	

	/**
	 * Default Empty Constructor for class Region
	 * 
	 * 
	 */
	public RegionTbl () {
		super();
	}
	
	/**
	 * Default Key Fields Constructor for class Region
	 */
	public RegionTbl (
		 Integer in_regionId
        ) {
		this.setRegionId(in_regionId);
    }

	

	public Region getParent() {
		return parent;
	}
	public void setParent(Region parent) {
		this.parent = parent;
	}
	public Integer getParentId() {
		return this.getParent()==null?null:this.getParent().getRegionId();
	}
	public void setParentId(Integer aValue) {
	    if (aValue==null) {
	    	parent = null;
	    } else {
	        parent = new Region(aValue);
	        parent.setVersion(Integer.valueOf(0));//set a version to cheat hibernate only
	    }
	}	
	
	public Set getChildren() {
		// 显示激活的，不显示删除了的子节点
		/**
		 * 特别注意：使用manager去获得子区域，而不使用.hbm去配置，是因为在同时使用事务Manager.doX和region.getFullName的时候，会自动加载了children集合,即使配置了延迟加载也不起作用，所以.hbm去除配置children
		 */
		RegionManager regionManager = (RegionManager) ContextUtil.getSpringBeanById("regionManager");
		children = regionManager.getChildrenByRegionId(this.regionId);
		return children;
	}
	public void setChildren(Set children) {
		this.children = children;
	}
	public java.util.Set getRegionItems () {
		return regionItems;
	}	
	
	public void setRegionItems (java.util.Set in_regionItems) {
		this.regionItems = in_regionItems;
	}
	

	public Set getRegionSubItems() {
		return regionSubItems;
	}

	public void setRegionSubItems(Set regionSubItems) {
		this.regionSubItems = regionSubItems;
	}

	public java.util.Set getShippingRates () {
		return shippingRates;
	}	
	
	public void setShippingRates (java.util.Set in_shippingRates) {
		this.shippingRates = in_shippingRates;
	}
    

	/**
	 * @return Integer
     * @hibernate.id column="regionId" type="java.lang.Integer" generator-class="native"
	 */
	public Integer getRegionId() {
		return this.regionId;
	}
	
	/**
	 * Set the regionId
	 */	
	public void setRegionId(Integer aValue) {
		this.regionId = aValue;
	}	

	/**
	 * @return String
	 * @hibernate.property column="regionCode" type="java.lang.String" length="8" not-null="false" unique="false"
	 */
	public String getRegionCode() {
		return this.regionCode;
	}
	
	/**
	 * Set the regionCode
	 */	
	public void setRegionCode(String aValue) {
		this.regionCode = aValue;
	}	

	/**
	 * @return Integer
	 * @hibernate.property column="regionType" type="java.lang.Integer" length="11" not-null="false" unique="false"
	 */
	public Integer getRegionType() {
		return this.regionType;
	}
	
	/**
	 * Set the regionType
	 */	
	public void setRegionType(Integer aValue) {
		this.regionType = aValue;
	}	

	/**
	 * @return String
	 * @hibernate.property column="regionName" type="java.lang.String" length="32" not-null="false" unique="false"
	 */
	public String getRegionName() {
		return this.regionName;
	}
	
	/**
	 * Set the regionName
	 */	
	public void setRegionName(String aValue) {
		this.regionName = aValue;
	}	

	/**
	 * @return String
	 * @hibernate.property column="zipCode" type="java.lang.String" length="8" not-null="false" unique="false"
	 */
	public String getZipCode() {
		return this.zipCode;
	}
	
	/**
	 * Set the zipCode
	 */	
	public void setZipCode(String aValue) {
		this.zipCode = aValue;
	}	

	/**
	 * @return String
	 * @hibernate.property column="telephoneCode" type="java.lang.String" length="8" not-null="false" unique="false"
	 */
	public String getTelephoneCode() {
		return this.telephoneCode;
	}
	
	/**
	 * Set the telephoneCode
	 */	
	public void setTelephoneCode(String aValue) {
		this.telephoneCode = aValue;
	}	


	/**
	 * @return String
	 * @hibernate.property column="description" type="java.lang.String" length="32" not-null="false" unique="false"
	 */
	public String getDescription() {
		return this.description;
	}
	
	/**
	 * Set the description
	 */	
	public void setDescription(String aValue) {
		this.description = aValue;
	}	

	
	public Short getStatus() {
		return status;
	}

	public void setStatus(Short status) {
		this.status = status;
	}

	public Integer getSortOrder() {
		return sortOrder;
	}
	public void setSortOrder(Integer sortOrder) {
		this.sortOrder = sortOrder;
	}
	

	public String getRegionIcon() {
		return regionIcon;
	}
	public void setRegionIcon(String regionIcon) {
		this.regionIcon = regionIcon;
	}
	/**
	 * @return Integer
	 * @hibernate.property column="version" type="java.lang.Integer" length="11" not-null="false" unique="false"
	 */
	public Integer getVersion() {
		return this.version;
	}
	
	/**
	 * Set the version
	 */	
	public void setVersion(Integer aValue) {
		this.version = aValue;
	}	

	/**
	 * @return Integer
	 * @hibernate.property column="createBy" type="java.lang.Integer" length="11" not-null="false" unique="false"
	 */
	public Integer getCreateBy() {
		return this.createBy;
	}
	
	/**
	 * Set the createBy
	 */	
	public void setCreateBy(Integer aValue) {
		this.createBy = aValue;
	}	

	/**
	 * @return java.util.Date
	 * @hibernate.property column="createTime" type="java.util.Date" length="19" not-null="false" unique="false"
	 */
	public java.util.Date getCreateTime() {
		return this.createTime;
	}
	
	/**
	 * Set the createTime
	 */	
	public void setCreateTime(java.util.Date aValue) {
		this.createTime = aValue;
	}	

	/**
	 * @return Integer
	 * @hibernate.property column="updateBy" type="java.lang.Integer" length="11" not-null="false" unique="false"
	 */
	public Integer getUpdateBy() {
		return this.updateBy;
	}
	
	/**
	 * Set the updateBy
	 */	
	public void setUpdateBy(Integer aValue) {
		this.updateBy = aValue;
	}	

	/**
	 * @return java.util.Date
	 * @hibernate.property column="updateTime" type="java.util.Date" length="19" not-null="false" unique="false"
	 */
	public java.util.Date getUpdateTime() {
		return this.updateTime;
	}
	
	/**
	 * Set the updateTime
	 */	
	public void setUpdateTime(java.util.Date aValue) {
		this.updateTime = aValue;
	}	

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof Region)) {
			return false;
		}
		Region rhs = (Region) object;
		return new EqualsBuilder()
				.append(this.regionId, rhs.regionId)
				.append(this.regionCode, rhs.regionCode)
				.append(this.regionType, rhs.regionType)
				.append(this.regionName, rhs.regionName)
				.append(this.zipCode, rhs.zipCode)
				.append(this.telephoneCode, rhs.telephoneCode)
				.append(this.description, rhs.description)
				.append(this.status, rhs.status)
				.append(this.version, rhs.version)
				.append(this.createBy, rhs.createBy)
				.append(this.createTime, rhs.createTime)
				.append(this.updateBy, rhs.updateBy)
				.append(this.updateTime, rhs.updateTime)
				.isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(-82280557, -700257973)
				.append(this.regionId) 
				.append(this.regionCode) 
				.append(this.regionType) 
				.append(this.regionName) 
				.append(this.zipCode) 
				.append(this.telephoneCode) 
				.append(this.description) 
				.append(this.status) 
				.append(this.version) 
				.append(this.createBy) 
				.append(this.createTime) 
				.append(this.updateBy) 
				.append(this.updateTime) 
				.toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this)
				.append("regionId", this.regionId) 
				.append("regionCode", this.regionCode) 
				.append("regionType", this.regionType) 
				.append("regionName", this.regionName) 
				.append("zipCode", this.zipCode) 
				.append("telephoneCode", this.telephoneCode) 
				.append("description", this.description) 
				.append("status", this.status) 
				.append("version", this.version) 
				.append("createBy", this.createBy) 
				.append("createTime", this.createTime) 
				.append("updateBy", this.updateBy) 
				.append("updateTime", this.updateTime) 
				.toString();
	}

	/**
	 * Return the name of the first key column
	 */
	public String getFirstKeyColumnName() {
		return "regionId";
	}
	
}